***********************************************************************
* Is Terrorism Necessarily Violent? Public Perceptions of Nonviolence * 
* and Terrorism in Conflict Settings      							  *
*                                                                     *
* Avishay Ben Sasson-Gordis & Alon Yakter  							  *
* Political Science Research and Methods (2023)		  				  *
*                                                                     *
* Replication code - US experiment 	    							  * ***********************************************************************
* The analysis was performed with Stata 17. 						  *
*																	  *
* To load the data (the "use" command), users should place the .dta	  *
* file in their Stata working directory (or type the full file 		  *
* paths as saved on their computer).                      			  *
***********************************************************************

**********************************************
* installing necessary user-written packages *
**********************************************
ssc install estout, replace
ssc install grstyle, replace
ssc install mplotoffset, replace
net install grc1leg2.pkg, from (http://digital.cgdev.org/doc/stata/MO/Misc/) replace

*****************
* Load US data 	*
*****************
use "BSG & Yakter PSRM - US survey-experiment data", replace

*****************************************************
* Influence of action type - by ideology (Figure 6) *
*****************************************************
* binary action - hetereognous effects, predicted value graphs
grstyle init
grstyle set legend, nobox
grstyle set plain, nogrid box
qui reg is_terror i.tr_nonviolence##i.ideology_lean i.attention
margins, at(ideology_lean=(1(1)3) tr_nonviolence=(0 1))
mplotoffset, recast(scatter) ///
	plot1opts(mcolor(black)) ci1opts(lcolor(black)) ///
	plot2opts(mcolor(black) msymbol(Oh)) ci2opts(lcolor(black)) ///
	legend(order(3 "Violence" 4 "Non-violence" )) ///
	yscale(range(2 10)) ylabel(2(2)10, labsize(medsmall)) ///
	xlabel(1 "Liberal" 2 "Neither" 3 "Cons.", labsize(medsmall)) ///
	ytitle("") 	xtitle("")  ///
	yline(5.5, lpattern(dash) lcolor(gr6)) ///
	title("Denotation", size(large)) ///
	name(terror_violence_pv, replace)
qui reg is_illegitimate i.tr_nonviolence##i.ideology_lean i.attention 
margins, at(ideology_lean=(1(1)3) tr_nonviolence=(0 1))
mplotoffset, recast(scatter) ///
	plot1opts(mcolor(black)) ci1opts(lcolor(black)) ///
	plot2opts(mcolor(black) msymbol(Oh)) ci2opts(lcolor(black)) ///
	legend(order(3 "Violence" 4 "Non-violence" )) ///
	yscale(range(2 10)) ylabel(2(2)10, labsize(medsmall)) ///
	xlabel(1 "Liberal" 2 "Neither" 3 "Cons.", labsize(medsmall)) ///
	ytitle("") 	xtitle("")  ///
	yline(5.5, lpattern(dash) lcolor(gr6)) ///
	title("Illegitimacy", size(large)) ///
	name(legitimate_violence_pv, replace)
qui reg use_force i.tr_nonviolence##i.ideology_lean i.attention
margins, at(ideology_lean=(1(1)3) tr_nonviolence=(0 1))
mplotoffset, recast(scatter) ///
	plot1opts(mcolor(black)) ci1opts(lcolor(black)) ///
	plot2opts(mcolor(black) msymbol(Oh)) ci2opts(lcolor(black)) ///
	legend(order(3 "Violence" 4 "Non-violence" )) ///
	yscale(range(2 10)) ylabel(2(2)10, labsize(medsmall)) ///
	xlabel(1 "Liberal" 2 "Neither" 3 "Cons.", labsize(medsmall)) ///
	ytitle("") 	xtitle("")  ///
	yline(5.5, lpattern(dash) lcolor(gr6)) ///
	title("Use of Force", size(large)) ///
	name(force_violence_pv, replace)
grc1leg2 terror_violence_pv legitimate_violence_pv force_violence_pv ///
	, rows(1) xcommon ycommon labsize(small) ///
	b2title("Ideology", size(medsmall)) ///
	l1title("Predicted Values",  size(medsmall)) ring(2) ///
	xsize(6) ysize(3) scale(1.4) ///
	name(combine_violence, replace)
graph export Figure6.pdf

**************************************************
* Influence of labeling - by ideology (Figure 7) *
**************************************************
qui reg is_terror i.tr_frame##i.ideology_lean i.attention 
margins, at(ideology_lean=(1(1)3) tr_frame=(0 1))
mplotoffset, recast(scatter) ///
	plot1opts(mcolor(black)) ci1opts(lcolor(black)) ///
	plot2opts(mcolor(black) msymbol(Oh)) ci2opts(lcolor(black)) ///
	legend(order(3 "No Label" 4 "Terror Label" )) ///
	yscale(range(2 10)) ylabel(2(2)10, labsize(medsmall)) ///
	xlabel(1 "Liberal" 2 "Neither" 3 "Cons.", labsize(medsmall)) ///
	ytitle("") 	xtitle("")  ///
	yline(5.5, lpattern(dash) lcolor(gr6)) ///
	legend(label(1 "No Label" 2 "Terror Label")) ///
	title("Denotation", size(large)) ///
	name(terror_label_pv, replace)
qui reg is_illegitimate i.tr_frame##i.ideology_lean i.attention
margins, at(ideology_lean=(1(1)3) tr_frame=(0 1))
mplotoffset, recast(scatter) ///
	plot1opts(mcolor(black)) ci1opts(lcolor(black)) ///
	plot2opts(mcolor(black) msymbol(Oh)) ci2opts(lcolor(black)) ///
	legend(order(3 "No Label" 4 "Terror Label" )) ///
	yscale(range(2 10)) ylabel(2(2)10, labsize(medsmall)) ///
	xlabel(1 "Liberal" 2 "Neither" 3 "Cons.", labsize(medsmall)) ///
	ytitle("") 	xtitle("")  ///
	yline(5.5, lpattern(dash) lcolor(gr6)) ///
	title("Illegitimacy", size(large)) ///
	name(legitimate_label_pv, replace)
qui reg use_force i.tr_frame##i.ideology_lean i.attention
margins, at(ideology_lean=(1(1)3) tr_frame=(0 1))
mplotoffset, recast(scatter) ///
	plot1opts(mcolor(black)) ci1opts(lcolor(black)) ///
	plot2opts(mcolor(black) msymbol(Oh)) ci2opts(lcolor(black)) ///
	legend(order(3 "No Label" 4 "Terror Label" )) ///
	yscale(range(2 10)) ylabel(2(2)10, labsize(medsmall)) ///
	xlabel(1 "Liberal" 2 "Neither" 3 "Cons.", labsize(medsmall)) ///
	ytitle("") 	xtitle("")  ///
	yline(5.5, lpattern(dash) lcolor(gr6)) ///
	title("Use of Force", size(large)) ///
	name(force_label_pv, replace)
grc1leg2 terror_label_pv legitimate_label_pv force_label_pv ///
	, rows(1) xcommon ycommon labsize(small) ///
	b2title("Ideology", size(medsmall)) ///
	l1title("Predicted Values",  size(medsmall)) ring(2) ///
	xsize(6) ysize(3) scale(1.4) ///
	name(combine_label, replace)
graph export Figure7.pdf

	
*******************************************
* Appendix: Sample tests and descriptives *
*******************************************
* balance tests by demography (Table B2)
****************************************
eststo clear
qui eststo: mlogit treatment_group i.sex i.agegr i.race i.edu i.ideology_lean ib1.attention, b(4)
esttab using TableB2.rtf, ///
	b(3) unstack nogaps noomitted not label noobs drop(1* 0*)

* power analysis (scores used for Table B3)
*******************************************
retrodesign 0.3 0.5 1 1.5, se(0.2) alpha(0.05) df(135)

* descriptive stats 
*******************
* summary for table (scores used for Table C2)
summarize is_terror is_illegitimate use_force i.ideology_lean attention if is_terror!=.
* distribution graphs (Figure C2)
graph bar (percent), ///
	over(is_terror, gap(*0.5) nolab) ///
	bar(1 ,color(black)) ytitle("Percent") ylabel(,nogrid) ///
	title("Denotation") name(is_terror_bar, replace)
graph bar (percent), ///
	over(is_illegitimate, gap(*0.5) nolab) ///
	bar(1 ,color(black)) ytitle("Percent") ylabel(,nogrid) ///
	title("Illegitimacy") name(is_illegitimate_bar, replace)
graph bar (percent), ///
	over(use_force, gap(*0.5) nolab) ///
	bar(1 ,color(black)) ytitle("Percent") ylabel(,nogrid) ///
	title("Use of Force") name(use_force_bar, replace)
graph bar (percent), ///
	over(ideology_lean, gap(*0.5) relabel(1 "Liberal" 2 "Neither" 3 "Conserv.")) ///
	bar(1 ,color(black)) ytitle("Percent") ylabel(,nogrid) ///
	title("Vote by Partisan Bloc") name(vote_bloc_rcl_bar, replace)
graph bar (percent), ///
	over(attention, gap(*0.5) relabel(1 "Failed"  2 "Passed")) ///
	bar(1 ,color(black)) ytitle("Percent") ylabel(,nogrid) ///
	title("Attention Check") name(attention_bar, replace)
graph combine is_terror_bar is_illegitimate_bar use_force_bar vote_bloc_rcl_bar attention_bar, ///
	col(3) ycommon
graph export FigureC2.pdf


***************************************
* Appendix: full models behind graphs *
***************************************
* violence vs nonviolence interacted with partisanship (Table D5)
eststo clear
qui eststo: reg is_terror i.tr_nonviolence##i.ideology_lean attention
qui eststo: reg is_illegitimate i.tr_nonviolence##i.ideology_lean attention
qui eststo: reg use_force i.tr_nonviolence##i.ideology_lean attention
esttab using TableD5.rtf, ///
	b(3) se(3) r2(3) nogaps compress ///
	drop(1.ideology_lean 1.tr_nonviolence#1.ideology_lean 0*) ///
	star(+ 0.1 * 0.05 ** 0.01 *** 0.001) ///
	order(_cons 1.tr_nonviolence 2.ideology_lean 3.ideology_lean 1.tr_nonviolence#2.ideology_lean ///
		1.tr_nonviolence#3.ideology_lean attention) ///
	coeflabels(1.tr_nonviolence Non-violence 2.ideology_lean Neither 3.ideology_lean Right ///
		1.tr_nonviolence#2.ideology_lean Non-violenceXNeither 1.tr_nonviolence#3.ideology_lean ///
		Non-violenceXConservative attention Attention _cons Constant-Violence-Liberal) ///
	mtitles("Terror Denotation" "Illegitimacy" "Use Force") 

* terror label interacted with partisanship (Table D6)
eststo clear
qui eststo: reg is_terror i.tr_frame##i.ideology_lean attention
qui eststo: reg is_illegitimate i.tr_frame##i.ideology_lean attention 
qui eststo: reg use_force i.tr_frame##i.ideology_lean attention 
esttab using TableD6.rtf, ///
	b(3) se(3) r2(3) nogaps compress ///
	drop(1.ideology_lean 1.tr_frame#1.ideology_lean 0*) ///
	star(+ 0.1 * 0.05 ** 0.01 *** 0.001) ///
	order(_cons 1.tr_frame 2.ideology_lean 3.ideology_lean 1.tr_frame#2.ideology_lean ///
		1.tr_frame#3.ideology_lean attention) ///
	coeflabels(1.tr_frame Terror_Label 2.ideology_lean Neither 3.ideology_lean Right ///
		1.tr_frame#2.ideology_lean Terror_LabelXNeither 1.tr_frame#3.ideology_lean ///
		Terror_LabelXConservative attention Attention _cons Constant-No_Label-Liberal) ///
	mtitles("Terror Denotation" "Illegitimacy" "Use Force") 

